import time
from datetime import datetime, timedelta


def insert_by_file():
    """
    将信息写入txt文件
    @return: None
    """
    with open('mysql_data.txt', 'w') as f:
        for i in range(10000):
            data_time = datetime(2021, 1, 1, 0, 0)
            for _ in range(96 * 10):
                content = f"{1000000 + i},{str(data_time)},1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234," \
                          f"1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234," \
                          f"1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234," \
                          f"1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234,1.234," \
                          f"1.234,1.234,1.234,1.234,1.234,1.234,1.234,1,1,{str(data_time.timestamp())},15\n"
                f.write(content)
                data_time += timedelta(minutes=15)


if __name__ == '__main__':
    time_start = time.time()
    insert_by_file()
    time_end = time.time()
    res = time_end - time_start
    print(res)
    # 执行完后去所在mysql服务器执行 load data infile '/home/mysql_data.txt' into table xlcloud.ods_device_electric_ts223 fields
    # terminated by ',' enclosed by '"' lines terminated by '\n';
